package leetcode_week.leetcode_week_01.question1;

import java.util.HashMap;
import java.util.Set;

class Solution {
    public boolean partitionArray(int[] nums, int k) {
//        1. 判断每个组含有k个元素
        int n = nums.length;
        if (n % k != 0) return false;
        int num = n / k;
//        2. 每组不能有重复元素
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i : nums){
            map.put(i,map.getOrDefault(i,0)+1);
        }
        Set<Integer> keySet = map.keySet();
        for(int i : keySet){
            int count = map.get(i);
            if (count > num) return false;
        }
        return true;
    }

    public static void main(String[] args) {
//        [74,103,74]
        int[] nums = {74, 103, 74};
        int k =3;
        System.out.println(new Solution().partitionArray(nums,k));
    }
}